package com.meritdata.cloud.data.standard.table.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.meritdata.cloud.data.base.ResultData;
import com.meritdata.cloud.data.standard.table.service.IDictValueService;
import com.meritdata.cloud.utils.SessionUtils;

@RestController
@RequestMapping("/dict/value")
public class DictValueController {

	@Autowired
	private IDictValueService dictValueService;

	@Autowired
	private SessionUtils sessionUtils;

	@RequestMapping("/page")
	public ResultData page(HttpServletRequest request, @RequestParam long dictId, @RequestParam int pageNum,
			@RequestParam int pageSize , @RequestParam String name) {
		return dictValueService.page(dictId, pageNum, pageSize, name);
	}

	@RequestMapping("/delete")
	public ResultData delete(HttpServletRequest request, @RequestParam long commonId) {
		return dictValueService.delete(commonId);
	}

	@SuppressWarnings("unchecked")
	@RequestMapping("/modify")
	public ResultData modify(HttpServletRequest request, @RequestParam long dictId, @RequestParam String values) {
		List<Map<String, Object>> valObjs = (List<Map<String, Object>>) JSON.parseObject(values, List.class);
		return dictValueService.modify(valObjs, dictId, sessionUtils.getCurrentUserId());
	}

}
